/*
 * peerList.c
 *
 *  Created on: 2010-3-11
 *      Author: abc
 */


#include "peerList.h"


pclientinfo CreateLinkList(void){
	pclientinfo ci = (pclientinfo)malloc(sizeof(clientinfo));
	ci->next = NULL;
	return ci;
}

void deletelist(pclientinfo L ,char* name){
	pclientinfo temp = L;
	pclientinfo temp2 = temp;
	while((strcmp(temp->name,name)!=0)&&temp->next != NULL){
			temp2 = temp;
			temp = temp->next;
	}
	if(temp->next == NULL && (strcmp(temp->name,name) != 0)){
		return;
	}
	else{
		temp2->next = temp->next;
		free(temp);
	}
}

void insertend(pclientinfo L, pclientinfo M){
		pclientinfo s,p;
		p = L;
		while(p->next != NULL)
		{
			p = p->next;
		}

		s = (pclientinfo)malloc(sizeof(clientinfo));
		memcpy(s,M,sizeof(clientinfo));
		s->next = p->next ;
		p->next =s;
}


int isexisted(pclientinfo L, char* name){
	pclientinfo p;
	p = L;
	while(p != NULL){
		if((strcmp(p->name,name)==0)){
			break;
		}
		p = p->next;
	}
	if(p == NULL){
		return -1;
	}
	return 1;
}



void DisplayList(pclientinfo L){
	    L=L->next;
		int i = 1;
		while (L != NULL)
		{
			printf("%d. %s %s  \n",i,L->name,inet_ntoa(L->addr_in.sin_addr));
			L = L->next;
			i++;
		}
}
